usingnamespace std; classSolution { public: boolsearchMatrix(vector<vector<int>>& matrix, int target){ int rows=matrix.size(),cols=matrix[0].size(); int start; int col=0,row=rows-1; while(col<cols && row>=0){ start=matrix[row][col]; if (start==target) returntrue; if (start>target) row--; else col++; } } };
intmain(){ vector<vector<int>>arr={{1,4,7,11,15},{2,5,8,12,19},{3,6,9,16,22},{10,13,14,17,24},{18,21,23,26,30}}; int target=5; Solution s; s.searchMatrix(arr,target); return0; }